package test.orwapkg;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class StreamReader {
	public static void main(String arg[]){
		String path = "D:\\temp.data";
		try {
			FileInputStream fis = new FileInputStream(path);
			DataInputStream dis = new DataInputStream(fis);
			FileOutputStream fos = new FileOutputStream(path);
			DataOutputStream dos = new DataOutputStream(fos);
			
			char charVal = 'c'; 
			dos.writeChar(charVal);
			dos.writeChar('a');
			dos.writeChar('r');
			
			//System.out.println(dis.available());
			for(int i=0;i<=dis.available();i++ ){
				System.out.print(dis.readChar());
			}
			
			dos.writeInt(1);
			dos.writeDouble(1000.001);
			//dis.close();
			dos.close();
			
			DataInputStream dis1 = new DataInputStream(new FileInputStream(path));
			DataOutputStream dos1 = new DataOutputStream(new FileOutputStream("D:\\temp2.data"));
			for(int i=0;i<=dis1.available();i++ ){
				dos1.write(dis1.read());
			}
			
			
			System.out.println(dis.available());
			System.out.println(dis1.available());
			//System.out.println(new DataInputStream(new FileInputStream(path)).available());
			
			//testing copying by fileStream
			FileInputStream fis1 = new FileInputStream(path);
			FileOutputStream fos1 = new FileOutputStream("D:\\temp3.data");
			
			int posBytes;
			byte[] buffer = new byte[1024];
			while((posBytes = fis1.read(buffer)) != -1){
				System.out.println("########" + posBytes);
				fos1.write(buffer, 0, posBytes);
			}
			
			dis.close();
			dis1.close();
			dos1.close();
			fis1.close();
			fos1.close();

		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
	}

}
